package com.ruoyi.recommend.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.recommend.service.INavigateService;
import com.ruoyi.recommend.service.INavigateService;
import com.ruoyi.recommend.service.impl.NavigateServiceImpl;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.recommend.domain.Navigate;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 导航栏Controller
 *
 * @author wwh
 * @date 2023-07-23
 */
@RestController
@RequestMapping("/recommend/navigate")
public class NavigateController extends BaseController
{
    @Autowired
    private INavigateService navigateService;

    /**
     * 查询导航栏列表
     */
    @PreAuthorize("@ss.hasPermi('navigate:navigate:list')")
    @GetMapping("/list")
    public TableDataInfo list(Navigate navigate)
    {
        startPage();
        List<Navigate> list = navigateService.selectNavigateList(navigate);
        return getDataTable(list);
    }

    /**
     * 导出导航栏列表
     */
    @PreAuthorize("@ss.hasPermi('navigate:navigate:export')")
    @Log(title = "导航栏", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Navigate navigate)
    {
        List<Navigate> list = navigateService.selectNavigateList(navigate);
        ExcelUtil<Navigate> util = new ExcelUtil<Navigate>(Navigate.class);
        util.exportExcel(response, list, "导航栏数据");
    }

    /**
     * 获取导航栏详细信息
     */
    @PreAuthorize("@ss.hasPermi('navigate:navigate:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(navigateService.selectNavigateById(id));
    }

    /**
     * 新增导航栏
     */
    @PreAuthorize("@ss.hasPermi('navigate:navigate:add')")
    @Log(title = "导航栏", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Navigate navigate)
    {
        navigate.setCreateBy(super.getUsername());
        navigate.setUpdateBy(super.getUsername());
        return toAjax(navigateService.insertNavigate(navigate));
    }

    /**
     * 修改导航栏
     */
    @PreAuthorize("@ss.hasPermi('navigate:navigate:edit')")
    @Log(title = "导航栏", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Navigate navigate)
    {
        navigate.setUpdateBy(super.getUsername());
        return toAjax(navigateService.updateNavigate(navigate));
    }

    /**
     * 删除导航栏 假删除 修改状态
     */
    @PreAuthorize("@ss.hasPermi('navigate:navigate:remove')")
    @Log(title = "导航栏", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(navigateService.deleteNavigateByIds(ids));
    }
}